<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>求助案例搜索</title>
	</head>
	<body>
		<center>
			<p><input style="font-size:2em" id="keyword" onkeyup="if(value!=defaultValue){detailCallback();defaultValue=value}"></p>
			<p><button style="font-size:1.5em" type=button onclick="detailCallback()">搜 索</button></p>
			<p id="tips"></p>
			<div id="table"></div>
		</center>
	</body>
<script>
var detailData;
var lastOrderBy;
function times33(str){
    for(var i = 0, len = str.length,hash = 5381; i < len; ++i){
       hash += (hash << 5) + str.charCodeAt(i);
    };
    return hash & 0x7fffffff;
}
function sortData(column){
	if(column!=lastOrderBy){
		lastOrderBy=column
		detailData.sort(function(a,b){return a[column]>b[column]?-1:1});
	}else{
		detailData.reverse();
	}
	detailCallback();
}
function caseCallback(){
	alert("如果不知道密钥可以资讯赵翔或者珍珠姐")
}
function detailCallback(data){
	if(location.hash.length<3){
		location.hash=document.getElementById("keyword").value;
		location.reload();
	}
	var keyWord="",matchTimes=0,r=null;
	if(data){
		var t=[]
		for(var i=0;i<data.length;i++){
			if(data[i].types.indexOf("xinye")>-1){
				t.push(data[i])
			}
		}
		data=detailData=t;
	}else{
		data=detailData;
		keyWord=document.getElementById("keyword").value.replace(/^\s*|\s*$|/g,"");
		if(keyWord){
			matchTimes=0;
			r=new RegExp("("+keyWord+")","ig")
		}
	}
	var columns=["helpSeeker","phoneOfHelpSeeker","family","phone","status","datauirements","address"]
	var columnNames=["求助者","求助者电话","家人","家人电话","现状","需求","地址"]
	var html = ["<table bgcolor=black cellspacing=1px><tbody bgcolor=white><tr onclick='sortData(event.target.title)'>"]
	for(var i=0;i<columnNames.length;i++){
		html.push("<th><nobr title='"+columns[i]+"'>"+columnNames[i]+"</nobr></th>")
	}
	html.push("</tr>");
	if(keyWord){
		for(var i=0;i<data.length;i++){
			var ar=[];
			var match=false;
			for(var j=0;j<columns.length;j++){
				var t=data[i][columns[j]];
				ar.push("<td>"+(t?t.toString().replace(r,"<font color=red size='+2'>$1</font>"):"")+"</td>");
				if(r.test(t)){
					match=true;
					matchTimes++;
				}
			}
			if(match){
				html.push("<tr>"+ar.join("")+"</tr>");
			}
		}		
	}else{
		for(var i=0;i<data.length;i++){
			html.push("<tr>")
			for(var j=0;j<columns.length;j++){
				var t=data[i][columns[j]];
					html.push("<td>"+t+"</td>")
				}
			}
			html.push("</tr>")
		}				

	html.push("</tbody></table>");
	document.getElementById("tips").innerHTML=keyWord?("找到了 "+matchTimes+" 个匹配"):("共有 "+data.length+" 条记录")
	document.getElementById("table").innerHTML=html.join("");
}
var s=document.createElement("script");
s.src="//wuhan.citpu.cn/"+(location.hash.length>3?(times33("wu"+location.hash).toString(36)+times33("han"+location.hash).toString(36)):("allcases"))+".js";
document.body.appendChild(s)
</script>
</html>